SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO




ALTER     VIEW dbo.v_tt_book
AS
SELECT d.depotid, d.name AS depotname, tb.productid, p.code, p.name AS productname, 
      dk.name AS depotkindname, k1.kname AS typename, pt.name AS producttypename, 
      tb.topqty,tb.lowqty,
      tb.quantity, tb.factqty, f.fI_filid, f.FI_FilNM, p.spec, u.unitname, tb.usedqty,
      tb.custom1,tb.custom2,tb.custom3,tb.length,tb.width,tb.height
FROM dbo.tt_book tb 
  LEFT OUTER JOIN dbo.td_product p ON p.p_id = tb.productid 
  LEFT OUTER JOIN dbo.td_depot d ON d.depotid = tb.depotid 
  LEFT OUTER JOIN dbo.td_filiale f ON f.FI_FilID = d.filid 
  LEFT OUTER JOIN dbo.td_unitprice u ON u.productid = p.p_id 
  LEFT OUTER JOIN dbo.td_depotkind dk ON dk.depotkindid = p.depotkindid 
  LEFT OUTER JOIN dbo.td_producttype pt ON pt.id = p.producttypeid 
  LEFT OUTER JOIN dbo.ts_kind k1 ON k1.kid = p.kind and k1.kind = 5104
  LEFT OUTER JOIN dbo.ts_kind k2 ON k2.kid = p.calccost and k2.kind = 5102
  LEFT OUTER JOIN dbo.ts_kind k3 ON k3.kid = dk.kind and k3.kind = 5104
WHERE (u.baseunit = 1)






GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

